package com.qqb.controller;

import com.qqb.pojo.Edu;
import com.qqb.service.EduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/edu")
public class EduController {

    @Autowired
    private EduService eduService;

    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 从redis中查询所有学历列表，如果缓存中不存在，再去数据库中查找
     *
     * @return
     */
    @GetMapping("/findAll")
    public List<Edu> findAll() {
        List<Edu> eduList;
        eduList = (List<Edu>) redisTemplate.boundValueOps("Edu").get();
        if (eduList == null || eduList.isEmpty()) {
            eduList = eduService.findAll();
        }
        return eduList;
    }

}
